﻿@{
    ViewBag.Title = ViewData["Action"].ToString() + " Project - Project Management System";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@ViewData["Action"].ToString() Project</h2>
<form id="form" action="" method="post">
<input type="hidden" id="url" name="url" />
<input type="hidden" id="Action" name="Action" />
<input type="hidden" id="ScheduleID" name="ScheduleID" />
<input type="hidden" id="GroupID" name="GroupID" />
<input type="hidden" id="ProjectID" name="ProjectID" value="@ViewData["ProjectID"]"/>
<input type="hidden" id="SemesterID" name="SemesterID" value="@ViewData["SemesterID"]" />
<div class="content-box" id="Project">
    <!-- Start Content Box -->
    <div class="content-box-header">
        <h3>
            Project Info</h3>
        <div class="clear">
        </div>
    </div>
    <!-- End .content-box-header -->
    <div class="content-box-content">
        @{ if (TempData["Message"] != null)
           {
            <div class="notification png_bg" id="messageBox">
                <a href="#" class="close">
                    <img src="../../Content/images/icons/cross_grey_small.png" title="Close this notification"
                        alt="close" /></a>
                <div>
                    @TempData["Message"].ToString()
                </div>
            </div>
           }
        }
        <fieldset>
            <p>
                <input type="hidden" id="txtProjectID" name="ProjectID" value="@Model.ProjectID" />
                <label class="width12 floatLeft">
                    Project Name:</label>
                <input type="text" id="txtProjectName" name="ProjectName" class="width20 input-inline text-input medium-input" value="@Model.ProjectName"/>
            </p>
            <div class="childCol">
                @*   <p>
                    <label class="width12 floatLeft">
                        Start Date:</label>
                    <input type="text" id="txtStartDate"  class="DateTime width20 input-inline text-input" value="@Model.StartDate.ToString("dd/MM/yyyy")"  />
                    <input type="hidden" id="htxtStartDate" name ="StartDate" value="@Model.StartDate.ToString("yyyy/MM/dd")"/>
                </p>*@
                <p>
                    <label class="width12 floatLeft">
                        Deparment:</label>
                    @Html.DropDownList("DepartmentID", (SelectList)ViewData["DepartmentList"], new { @class = "width20 input-inline" })
                </p>
                <p>
                    <label class="width12 floatLeft">
                        Number of Group:</label>
                    <input type="text" id="txtNumberOfGroup" name="NumberOfGroup" class="width20 input-inline text-input DENumber" value="@Model.NumberOfGroup"/>
                </p>
            </div>
            <div class="childCol">
                @* <p>
                    <label class="width12 floatLeft">
                        End Date:</label>
                    <input type="text" id="txtEndDate" class="DateTime width20 input-inline text-input " value="@Model.EndDate.ToString("dd/MM/yyyy")"/>
                    <input type="hidden" id="htxtEndDate" name ="EndDate" value="@Model.EndDate.ToString("yyyy/MM/dd")"  />
                </p>*@
                <p>
                    <label class="width12 floatLeft">
                        Subject:</label>
                    @Html.DropDownList("SubjectID", (SelectList)ViewData["SubjectList"], new { @class = "width20 input-inline" })
                </p>
                <p>
                    <label class="width12 floatLeft">
                        Max Member:</label>
                    <input type="text" id="txtMaxMemOfGroup" name="MaxMemOfGroup" class="width20 input-inline text-input DENumber " value="@Model.MaxmemOfGroup"/>
                </p>
            </div>
            <br clear="all" />
            <p>
                <label class="width12 floatLeft">
                    Description:</label>
                <textarea class="text-input textarea" id="txtDescription" name="Description" cols="79"
                    rows="15">@Model.Description</textarea>
                <input type="hidden" id="txtStatus" name="Status" value="@Model.Status" />
                <input type="hidden" id="txtOwnerID" name="OwnerID" value="@Model.OwnerID" />
            </p>
            <p>
                @{if (ViewData["Action"].ToString() != PMS.ENT.ActionName.View.ToString())
                  {
                    <input class="button" type="submit" value="Submit" id="btnSubmit" />
                  }
                }
                <input class="button" type="button" value="Back to list" id="btnBack" onclick="DoUrl('@Url.Action("ManageProject", "Project")')" />
            </p>
        </fieldset>
    </div>
</div>
@{if (ViewData["Action"].ToString() == PMS.ENT.ActionName.View.ToString() && ViewData["GroupList"] != null)
  {
    <div class="content-box">
        <!-- Start Content Box -->
        <div class="content-box-header">
            <h3>
                Group List</h3>
            <div class="clear">
            </div>
        </div>
        <!-- End .content-box-header -->
        <div class="content-box-content">
            <div>
                <!-- This is the target div. id must match the href of this div's tab -->
                @{ 
      PMS.ENT.GroupCollection listGroup = (PMS.ENT.GroupCollection)ViewData["GroupList"];
      var pageSize = int.Parse(ViewData[PMS.ENT.PageInfo.PageSize.ToString()].ToString());
      var pageNum = int.Parse(ViewData[PMS.ENT.PageInfo.PageNum.ToString()].ToString());
      var page = int.Parse(ViewData[PMS.ENT.PageInfo.Page.ToString()].ToString()); 
                }
                <input type="hidden" name="joinScheduleID" id="JoinScheduleID" />
                <input type="hidden" value="@ViewData["OrderBy"]" name="orderBy" id="orderBy" />
                <input type="hidden" value="@ViewData["OrderDirection"]" name="orderDirection"
                id="orderDirection" />
                @{if (listGroup.Count <= 0)
                  {
                    <div class="RecordFound @("RecordFound" + @listGroup.Count)">
                        No Record Found</div>
                  }
                }
                <table class="flexigird TableGrid">
                    <thead>
                        <tr>
                           
                            <th id="GroupName">
                                Group Name
                            </th>
                            <th id="Owner">
                                Team Leader
                            </th>
                            <th id="Member">
                                Member
                            </th>
                            <th id="SStatus">
                                Accepted
                            </th>
                        </tr>
                    </thead>
                    @*<tfoot>
                    <tr>
                        <td colspan="6">
                            @{ Html.RenderPartial("Pagination", null, ViewData); }
                            <!-- End .pagination -->
                            <div class="clear">
                            </div>
                        </td>
                    </tr>
                </tfoot>*@
                    <tbody>
                        @{ for (int i = 0; i < listGroup.Count; i++)
                           {
                               string groupname = @listGroup[i].GroupName;
                            <tr>
                                
                                <td>
                                    @Html.ActionLink(groupname, "ViewGroup", new { ID = listGroup[i].GroupID }, null)
                                </td>
                                <td>
                                    @listGroup[i].Owner
                                </td>
                                <td>
                                    @listGroup[i].Member
                                </td>
                                <td>
                                    @{if (listGroup[i].SStatus != "Accepted" && (bool)ViewData["Permission"] == true)
                                      {
                                        <a href="#" onclick="LoadSchedule(@listGroup[i].GroupID)" >Add Schedule</a>
                                      }
                                      else
                                      {
                                        @Html.Encode(listGroup[i].SStatus)
                                      } 
                                    }
                                </td>
                            </tr>
                           } 
                        }
                    </tbody>
                </table>
                @{Html.RenderPartial("Pagination", null, ViewData); }
            </div>
            <!-- End #tab1 -->
        </div>
        <!-- End .content-box-content -->
    </div>

  }
}
</form>
<script type="text/javascript">
    $("#url").val(document.URL);
    $("#MProject").addClass("current");
    $("#Project").addClass("current");

    $("#DepartmentID").change(function () {
        if ($(this).val() != null) {
            var DepartmentID = $("option:selected", this).val();
            $.post('@Url.Action("GetSubjectByDepartmentID", "Project")', { ID: DepartmentID }, function (data) {
                if (data != null) {
                    //Invoice To
                    var options = $("#SubjectID").attr('options');
                    $("#SubjectID").children().remove();
                    $.each(data.ListSubject, function (index, Subject) {
                        var option = new Option(Subject.SubjectName, Subject.SubjectID);
                        options[options.length] = option;
                    });
                }
            });
        }
    });

//    $(".DateTime").datepicker({
//        dateFormat: 'dd/mm/yy',
//        gotoCurrent: true,
//        changeMonth: true,
//        changeYear: true,
//        showStatus: true,
//        showWeeks: true,
//        highlightWeek: true,
//        numberOfMonths: 1,
//        showButtonPanel: true,
//        hideIfNoPrevNext: true,
//        showAnim: "scale",
//        showOptions: {
//            origin: ["top", "left"]
//        }
//    });

//    $("#ui-datepicker-div").css('display', 'none');
//    $(".DateTime").filter_inputDateTime(DateTimeFormat);
//    CheckDate('txtStartDate', 'txtEndDate', true);

    if(@Html.Raw(Json.Encode(ViewData["Action"])) == "View")
    {
        $(".input-inline").attr("disabled","disabled");
        $(".textarea").attr("disabled","disabled");
    }


     function LoadSchedule(id) {
        $("#GroupID").val(id);
        var semesterID = $("#SemesterID").val();
        var projectID = $("#ProjectID").val();
        jQuery.facebox(' <id>\
                    Add schedule to group</h3>\
                    <fieldset>\
                        <p>\
                            <label class="width12 floatLeft">\
                                Schedule:</label>\
                            <select class="width20 input-inline" id="cmbSchedule" >\
                                <option></option>\
                            </select>\
                        </p>\
                        <input class="button" type="button" value="Add" id="btnJoin" onclick="Join();" />\
                    </fieldset>'
        );
        $.post('@Url.Action("GetScheduleByProjectIDAndSemesterID", "Schedule")', { ProjectID: projectID, SemesterID: semesterID }, function (data) {
            if (data != null) {
                //Invoice To
                var options = $("#cmbSchedule").attr('options');
                $("#cmbSchedule").children().remove();
                $.each(data.ListSchedule, function (index, Schedule) {
                    var option = new Option(Schedule.ScheduleName, Schedule.ScheduleID);
                    options[options.length] = option;
                });
            }
           
        });
              
     }


     function Join () {
        var val = $("#cmbSchedule").val();
        $("#Action").val('Schedule');
        $("#ScheduleID").val(val);
        $('form').submit();
     };
</script>
